package com.pushwish.server;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class PushwishToGMail {
	private static final Logger log = Logger.getLogger(PushwishToGMail.class.getName());
	
	public void push(String message) throws IOException {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("ychun.w@gmail.com", "push-wish Admin"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress("guyuchun1969@gmail.com", "Mr. User"));
            msg.setSubject("Your have a new message from push-wish");
            msg.setText(message);
            Transport.send(msg);

        } catch (AddressException e) {
            log.severe(e.getMessage());
        } catch (MessagingException e) {
            log.severe(e.getMessage());
        }			
	}
}
